package com.xin.data.simbapesa.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.xin.data.simbapesa.base.BaseDialog;
import com.xin.data.simbapesa.databinding.SimbaPhotoBinding;
import com.xin.data.simbapesa.utils.ViewUtils;

public class PhotoDialog extends BaseDialog<SimbaPhotoBinding> {


    int type;

    public PhotoDialog(@NonNull Context context) {
        super(context);
    }

    public PhotoDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected PhotoDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected SimbaPhotoBinding initViewBinding(LayoutInflater inflater) {
        return SimbaPhotoBinding.inflate(inflater);
    }

    @Override
    protected void initView() {
        binding.tvBtn.setOnClickListener(v -> {
            if (binding.tvBtn.isSelected()) {
                ViewUtils.viewScale(v);
                dismiss();
                if (onBtnClickListener != null) {
                    onBtnClickListener.btnOnClickOk();
                }
            }
        });
        binding.tvClose.setOnClickListener(v -> {
            ViewUtils.viewScale(v);
            dismiss();
            if (onBtnClickListener != null) {
                onBtnClickListener.btnOnClickColse();
            }
        });
        binding.tvLayout1.setOnClickListener(v -> {
            ViewUtils.viewScale(v);
            switchState(1);
        });
        binding.tvLayout2.setOnClickListener(v -> {
            ViewUtils.viewScale(v);
            switchState(2);
        });

        binding.tvBox1.setClickable(false);
        binding.tvBox2.setClickable(false);
        binding.tvBox1.setFocusable(false);
        binding.tvBox2.setFocusable(false);
    }

    @Override
    public void show() {
        super.show();
        switchState(0);
    }

    public void switchState(int position) {
        type = position;
        if (type == 0) {
            binding.tvLayout1.setSelected(false);
            binding.tvLayout2.setSelected(false);
            binding.tvTitle1.setSelected(false);
            binding.tvTitle2.setSelected(false);
            binding.tvBox1.setVisibility(View.GONE);
            binding.tvBox2.setVisibility(View.GONE);
            binding.tvBtn.setSelected(false);
        } else if (type == 1) {
            binding.tvLayout1.setSelected(true);
            binding.tvLayout2.setSelected(false);
            binding.tvTitle1.setSelected(true);
            binding.tvTitle2.setSelected(false);
            binding.tvBox1.setVisibility(View.VISIBLE);
            binding.tvBox2.setVisibility(View.GONE);
            binding.tvBtn.setSelected(true);
        } else if (type == 2) {
            binding.tvLayout1.setSelected(false);
            binding.tvLayout2.setSelected(true);
            binding.tvTitle1.setSelected(false);
            binding.tvTitle2.setSelected(true);
            binding.tvBox1.setVisibility(View.GONE);
            binding.tvBox2.setVisibility(View.VISIBLE);
            binding.tvBtn.setSelected(true);
        }
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }


}
